// SPDX-License-Identifier: Apache-2.0

package chisel3.experimental

import scala.language.existentials
import chisel3.internal.Builder
import chisel3.{Data, InstanceId, RawModule}
import firrtl.annotations._
import firrtl.options.Unserializable
import firrtl.transforms.{DedupGroupAnnotation, DontTouchAnnotation, NoDedupAnnotation}

trait ChiselAnnotation {

  def toFirrtl: Annotation
}

trait ChiselMultiAnnotation {
  def toFirrtl: Seq[Annotation]
}

object annotate {
  def apply(anno: ChiselAnnotation): Unit = {
    Builder.annotations += anno
  }
  def apply(annos: ChiselMultiAnnotation): Unit = {
    Builder.newAnnotations += annos
  }
}

object doNotDedup {

  def apply[T <: RawModule](module: T): Unit = {
    annotate(new ChiselAnnotation { def toFirrtl = NoDedupAnnotation(module.toNamed) })
  }
}

object dedupGroup {

  def apply[T <: BaseModule](module: T, group: String): Unit = {
    annotate(new ChiselAnnotation { def toFirrtl = DedupGroupAnnotation(module.toTarget, group) })
  }
}
